<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Python3 基本数据类型 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../python3/python3-data-type.html" />
<meta name="keywords" content="Python3 基本数据类型">
<meta name="description" content="Python3 基本数据类型  Python 中的变量不需要声明。每个变量在使用前都必须赋值，变量赋值以后该变量才会被创建。 在 Python 中，变量就是变量，它没有类型，我们所说的“类型”是变量所指的内存中对象的类型。 等号（=）用来给变量赋值。 等号（=）运算符左边是一个变量名,等号（=）运算符右边是存储在变量中的值。例如：   实例(Python 3.0+)   [mycode4 type=&#039;python&#039;]..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<!-- 导航栏 -->
<div class="container navigation">
	<div class="row">
		<div class="col nav">
			<ul class="pc-nav" id="runoob-detail-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JavaScript</a></li>
				<li><a href="javascript:void(0);" data-id="vue">Vue</a></li>
				<li><a href="javascript:void(0);" data-id="bootstrap">Bootstrap</a></li>
				<li><a href="../nodejs/nodejs-tutorial.html">NodeJS</a></li>
				<li><a href="../python3/python3-tutorial.html">Python3</a></li>
				<li><a href="../python/python-tutorial.html">Python2</a></li>
				<li><a href="../java/java-tutorial.html">Java</a></li>
				<li><a href="../cprogramming/c-tutorial.html">C</a></li>
				<li><a href="../cplusplus/cpp-tutorial.html">C++</a></li>
				<li><a href="../csharp/csharp-tutorial.html">C#</a></li>
				<li><a href="../go/go-tutorial.html">Go</a></li>
				<li><a href="../sql/sql-tutorial.html">SQL</a></li>
				<li><a href="../linux/linux-tutorial.html">Linux</a></li>
				<li><a href="../jquery/jquery-tutorial.html">jQuery</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<!--
			
				<li><a href="../w3cnote/knowledge-start.html" style="font-weight: bold;" onclick="_hmt.push(['_trackEvent', '星球', 'click', 'start'])" title="我的圈子">我的圈子</a></li>				
				<li><a href="javascript:;" class="runoob-pop">登录</a></li>
				-->
      		</ul>
			<ul class="mobile-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JS</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<li><a href="javascript:void(0)" class="search-reveal">Search</a> </li>
			</ul>
			
		</div>
	</div>
</div>

<div class="container sub-navigation sub-navigation-articles" style="display:none">
	<div class="row">
		<div class="col nav-sub">
		<ul id="python">
			<li class="cat-item"><a href="../python3/python3-tutorial.html">Python3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../python/python-tutorial.html">Python2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		<ul id="vue">
			<li class="cat-item"><a href="../vue3/vue3-tutorial.html">Vue3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../vue/vue-tutorial.html">vue2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>

		<ul id="bootstrap">
			<li class="cat-item"><a href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap/bootstrap-v2-tutorial.html">Bootstrap2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		</div>
	</div>
</div><!--  内容  -->
<div class="container main">
	<!-- 中间 -->
	<div class="row">
	
<div class="runoob-col-md2">
<div class="left-column">
	<div class="tab" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
	<i class="fa fa-list" aria-hidden="true"></i> 
	<span>Python 3 教程</span>
	<a data-cate="124" href="javascript:void(0);" title="夜间模式"  id="moon"><i class="fa fa-moon-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;"></i></a>
	<a data-cate="124" style="display:none;" href="javascript:void(0);" title="日间模式"  id="sun" ><i class="fa fa-sun-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;line-height: 28px;
}"></i></a>

	</div>
	<div class="sidebar-box gallery-list">
		<div class="design" id="leftcolumn">
						<a target="_top" title="Python3 教程"  href="../python3/python3-tutorial.html" >
			Python3 教程			</a>
			<a target="_top" title="Python3 简介" href="python3-intro.html" > Python3 简介 </a>
<a target="_top" title="Python3 环境搭建" href="python3-install.html" > Python3 环境搭建</a>
<a target="_top" title="Python3 VScode" href="python-vscode-setup.html"> Python3 VScode </a>
<a target="_top" title="Python3 基础语法" href="python3-basic-syntax.html" > Python3 基础语法 </a>
<a target="_top" title="Python3 基本数据类型" href="python3-data-type.html" > Python3 基本数据类型 </a>
<a target="_top" title="Python3  数据类型转换" href="python3-type-conversion.html" > Python3 数据类型转换 </a>
			<a target="_top" title="Python3 解释器"  href="../python3/python3-interpreter.html" >
			Python3 解释器			</a>
						<a target="_top" title="Python3 注释"  href="../python3/python3-comment.html" >
			Python3 注释			</a>
			<a target="_top" title="Python3 运算符" href="python3-basic-operators.html"> Python3 运算符 </a>			<a target="_top" title="Python3 数字(Number)"  href="../python3/python3-number.html" >
			Python3 数字(Number)			</a>
						<a target="_top" title="Python3 字符串"  href="../python3/python3-string.html" >
			Python3 字符串			</a>
						<a target="_top" title="Python3 列表"  href="../python3/python3-list.html" >
			Python3 列表			</a>
			<a target="_top" title="Python3 元组" href="python3-tuple.html"> Python3 元组 </a>
<a target="_top" title="Python3 字典" href="python3-dictionary.html"> Python3 字典</a>
<a target="_top" title="Python3 集合" href="python3-set.html"> Python3 集合</a>			<a target="_top" title="Python3 条件控制"  href="../python3/python3-conditional-statements.html" >
			Python3 条件控制			</a>
						<a target="_top" title="Python3 循环语句"  href="../python3/python3-loop.html" >
			Python3 循环语句			</a>
			<a target="_top" title="Python3 编程第一步" href="python3-step1.html"> Python3 编程第一步</a>
<a target="_top" title="Python3 推导式" href="python-comprehensions.html" > Python3 推导式 </a>
<a target="_top" title="Python3 迭代器与生成器" href="python3-iterator-generator.html"> Python3 迭代器与生成器</a>			<a target="_top" title="Python3 函数"  href="../python3/python3-function.html" >
			Python3 函数			</a>
						<a target="_top" title="Python3 数据结构"  href="../python3/python3-data-structure.html" >
			Python3 数据结构			</a>
						<a target="_top" title="Python3 模块"  href="../python3/python3-module.html" >
			Python3 模块			</a>
						<a target="_top" title="Python3 输入和输出"  href="../python3/python3-inputoutput.html" >
			Python3 输入和输出			</a>
			<a target="_top" title="Python3 File" href="python3-file-methods.html"> Python3 File </a>
<a target="_top" title="Python3 OS" href="python3-os-file-methods.html"> Python3 OS </a>			<a target="_top" title="Python3 错误和异常"  href="../python3/python3-errors-execptions.html" >
			Python3 错误和异常			</a>
						<a target="_top" title="Python3 面向对象"  href="../python3/python3-class.html" >
			Python3 面向对象			</a>
			<a target="_top" title=" Python3 命名空间/作用域" href="../python3/python3-namespace-scope.html"> Python3 命名空间/作用域</a>			<a target="_top" title="Python3 标准库概览"  href="../python3/python3-stdlib.html" >
			Python3 标准库概览			</a>
						<a target="_top" title="Python3 实例"  href="../python3/python3-examples.html" >
			Python3 实例			</a>
			<a target="_blank" title="Python 测验" href="../quiz/python-quiz.html"> Python 测验 </a>
<br><h2 class="left"><span class="left_h2">Python3</span> 高级教程</h2>			<a target="_top" title="Python3 正则表达式"  href="../python3/python3-reg-expressions.html" >
			Python3 正则表达式			</a>
						<a target="_top" title="Python3 CGI编程"  href="../python3/python3-cgi-programming.html" >
			Python3 CGI编程			</a>
			<a target="_top" title="Python MySQL - mysql-connector 驱动" href="python-mysql-connector.html">Python3 MySQL(mysql-connector)</a>			<a target="_top" title="Python3 MySQL 数据库连接 &#8211; PyMySQL 驱动"  href="../python3/python3-mysql.html" >
			Python3 MySQL(PyMySQL)			</a>
						<a target="_top" title="Python3 网络编程"  href="../python3/python3-socket.html" >
			Python3 网络编程			</a>
						<a target="_top" title="Python3 SMTP发送邮件"  href="../python3/python3-smtp.html" >
			Python3 SMTP发送邮件			</a>
						<a target="_top" title="Python3 多线程"  href="../python3/python3-multithreading.html" >
			Python3 多线程			</a>
						<a target="_top" title="Python3 XML 解析"  href="../python3/python3-xml-processing.html" >
			Python3 XML 解析			</a>
						<a target="_top" title="Python3 JSON 数据解析"  href="../python3/python3-json.html" >
			Python3 JSON			</a>
						<a target="_top" title="Python3 日期和时间"  href="../python3/python3-date-time.html" >
			Python3 日期和时间			</a>
						<a target="_top" title="Python3 内置函数"  href="../python3/python3-built-in-functions.html" >
			Python3 内置函数			</a>
						<a target="_top" title="Python MongoDB"  href="../python3/python-mongodb.html" >
			Python3 MongoDB			</a>
			<a target="_top" title="Python3 urllib" href="python-urllib.html"> Python3 urllib</a>			<a target="_top" title="Python uWSGI  安装配置"  href="../python3/python-uwsgi.html" >
			Python uWSGI  安装配置			</a>
						<a target="_top" title="Python3 pip"  href="../python3/python3-pip.html" >
			Python3 pip			</a>
						<a target="_top" title="Python3 operator 模块"  href="../python3/python-operator.html" >
			Python3 operator			</a>
						<a target="_top" title="Python math 模块"  href="../python3/python-math.html" >
			Python math			</a>
						<a target="_top" title="Python requests 模块"  href="../python3/python-requests.html" >
			Python requests			</a>
						<a target="_top" title="Python random 模块"  href="../python3/python-random.html" >
			Python random			</a>
						<a target="_top" title="Python 有用的资源"  href="../python3/python3-resources.html" >
			Python 有用的资源			</a>
						<a target="_top" title="Python AI 绘画"  href="../python3/python-ai-draw.html" >
			Python AI 绘画			</a>
				
		</div>
	</div>	
</div>
</div>	<div class="col middle-column">
		
	
	<div class="article">
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../python3/python3-basic-syntax.html" rel="prev"> Python3 基础语法</a> </div>
			<div class="next-design-link"><a href="../python3/python3-examples.html" rel="next"> Python3 实例</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
<div class="article-heading-ad" style="display: block;">
<script async src=""
     crossorigin="anonymous"></script>
<!-- 728*90 固定 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="2147566827"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
		<div class="article-body">
		
			<div class="article-intro" id="content">
			
			<h1>Python3 基本数据类型</h1>
<p>
Python 中的变量不需要声明。每个变量在使用前都必须赋值，变量赋值以后该变量才会被创建。</p>
<p>在 Python 中，变量就是变量，它没有类型，我们所说的"类型"是变量所指的内存中对象的类型。</p>
<p>等号（=）用来给变量赋值。</p><p>
等号（=）运算符左边是一个变量名,等号（=）运算符右边是存储在变量中的值。例如：</p>
<div class="example"> 
<h2 class="example">实例(Python 3.0+)</h2> 
<div class="example_code">

<span style="color: #a50">#!/usr/bin/python3</span><br />
<br />
counter <span style="color: Gray;">=</span> <span style="color: Maroon;">100</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 整型变量</span><br />
miles &nbsp; <span style="color: Gray;">=</span> <span style="color: Maroon;">1000.0</span> &nbsp; &nbsp; &nbsp; <span style="color: #a50"># 浮点型变量</span><br />
name &nbsp; &nbsp;<span style="color: Gray;">=</span> <span style="color: #a11;">&quot;runoob&quot;</span> &nbsp; &nbsp; <span style="color: #a50"># 字符串</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span>counter<span style="color: Olive;">&#41;</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span>miles<span style="color: Olive;">&#41;</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span>name<span style="color: Olive;">&#41;</span><br />

</div><br>
<a target="_blank" href="../try/runcode.php?filename=basic_data_type1&type=python3" class="showbtn" rel="noopener noreferrer">运行实例 »</a>
</div>
<p>执行以上程序会输出如下结果：</p>
<pre>
100
1000.0
runoob
</pre>
<h3>多个变量赋值</h3>
<p>
Python允许你同时为多个变量赋值。例如：</p>
<pre>
a = b = c = 1
</pre>
<p>
以上实例，创建一个整型对象，值为 1，从后向前赋值，三个变量被赋予相同的数值。
</p><p>
您也可以为多个对象指定多个变量。例如：</p><pre>
a, b, c = 1, 2, "runoob"</pre><p>
以上实例，两个整型对象 1 和 2 的分配给变量 a 和 b，字符串对象 "runoob" 分配给变量 c。</p>
<hr>
<h2>标准数据类型</h2>
<p>Python3 中常见的数据类型有：
</p>
<ul>
<li>Number（数字）</li>
<li>String（字符串）</li>
<li> bool（布尔类型）</li>

<li>List（列表）</li>
<li>Tuple（元组）</li>
<li>Set（集合）</li>
<li>Dictionary（字典）</li>
</ul>
<p>Python3 的六个标准数据类型中：</p><ul><li>
<strong>不可变数据（3 个）：</strong>Number（数字）、String（字符串）、Tuple（元组）；</li><li>
<strong>可变数据（3 个）：</strong>List（列表）、Dictionary（字典）、Set（集合）。
</li></ul>
<p>此外还有一些高级的数据类型，如: 字节数组类型(bytes)。</p>

<hr>
<h2>Number（数字）</h2>
<p>Python3 支持 <b>int、float、bool、complex（复数）</b>。
</p>
<p>在Python 3里，只有一种整数类型 int，表示为长整型，没有 python2 中的 Long。</p>
<p>像大多数语言一样，数值类型的赋值和计算都是很直观的。</p>
<p>内置的 type() 函数可以用来查询变量所指的对象类型。</p>
<pre>
&gt;&gt;&gt; a, b, c, d = 20, 5.5, True, 4+3j
&gt;&gt;&gt; print(type(a), type(b), type(c), type(d))
&lt;class 'int'&gt; &lt;class 'float'&gt; &lt;class 'bool'&gt; &lt;class 'complex'&gt;
</pre>

<p>此外还可以用 isinstance 来判断：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: Gray;">&gt;&gt;&gt;</span> a <span style="color: Gray;">=</span> <span style="color: Maroon;">111</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Teal;">isinstance</span><span style="color: Olive;">&#40;</span>a<span style="color: Gray;">,</span> <span style="color: Teal;">int</span><span style="color: Olive;">&#41;</span><br />
<span style="color: Teal;">True</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <br />

</div>
</div>
<p>
isinstance 和 type 的区别在于：</p>
<ul><li>
type()不会认为子类是一种父类类型。</li><li>
isinstance()会认为子类是一种父类类型。</li></ul>
<pre>
&gt;&gt;&gt; class A:
...     pass
... 
&gt;&gt;&gt; class B(A):
...     pass
... 
&gt;&gt;&gt; isinstance(A(), A)
True
&gt;&gt;&gt; type(A()) == A 
True
&gt;&gt;&gt; isinstance(B(), A)
True
&gt;&gt;&gt; type(B()) == A
False
</pre>


<blockquote>
<p><b>注意：</b>Python3 中，bool 是 int 的子类，True 和 False 可以和数字相加， <span class="marked">True==1、False==0</span> 会返回 <strong>True</strong>，但可以通过 <span class="marked">is</span> 来判断类型。</p>
<pre>
&gt;&gt;&gt; issubclass(bool, int) 
True
&gt;&gt;&gt; True==1
True
&gt;&gt;&gt; False==0
True
&gt;&gt;&gt; True+1
2
&gt;&gt;&gt; False+1
1
&gt;&gt;&gt; 1 is True
False
&gt;&gt;&gt; 0 is False
False
</pre>
<p>在 Python2 中是没有布尔型的，它用数字 0 表示 False，用 1 表示 True。</p>
</blockquote>
<p>当你指定一个值时，Number 对象就会被创建：</p>
<pre>
var1 = 1
var2 = 10
</pre><p>
您也可以使用del语句删除一些对象引用。</p><p>
del语句的语法是：</p>
<pre>
del var1[,var2[,var3[....,varN]]]
</pre>
<p>您可以通过使用del语句删除单个或多个对象。例如：</p>
<pre>
del var
del var_a, var_b</pre>
<h3>数值运算</h3>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Maroon;">5</span> + <span style="color: Maroon;">4</span> &nbsp;<span style="color: #a50"># 加法</span><br />
<span style="color: Maroon;">9</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Maroon;">4.3</span> - <span style="color: Maroon;">2</span> <span style="color: #a50"># 减法</span><br />
<span style="color: Maroon;">2.3</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Maroon;">3</span> * <span style="color: Maroon;">7</span> &nbsp;<span style="color: #a50"># 乘法</span><br />
<span style="color: Maroon;">21</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Maroon;">2</span> / <span style="color: Maroon;">4</span> &nbsp;<span style="color: #a50"># 除法，得到一个浮点数</span><br />
<span style="color: Maroon;">0.5</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Maroon;">2</span> // <span style="color: Maroon;">4</span> <span style="color: #a50"># 除法，得到一个整数</span><br />
<span style="color: Maroon;">0</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Maroon;">17</span> % <span style="color: Maroon;">3</span> <span style="color: #a50"># 取余 </span><br />
<span style="color: Maroon;">2</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Maroon;">2</span> ** <span style="color: Maroon;">5</span> <span style="color: #a50"># 乘方</span><br />
<span style="color: Maroon;">32</span><br />

</div>
</div>
<p><b>注意：</b></p>
<ul>
<li>1、Python可以同时为多个变量赋值，如a, b = 1, 2。</li><li>
2、一个变量可以通过赋值指向不同类型的对象。</li><li>
3、数值的除法包含两个运算符：<span class="marked">/</span> 返回一个浮点数，<span class="marked">//</span> 返回一个整数。</li><li>
4、在混合计算时，Python会把整型转换成为浮点数。
</li>
</ul>
<h3>数值类型实例</h3>
<table class="reference">
<tbody><tr><th>int</th><th>float</th><th>complex</th></tr>
<tr><td>10</td><td>0.0</td><td>3.14j</td></tr>
<tr><td>100</td><td>15.20</td><td>45.j</td></tr>
<tr><td>-786</td><td>-21.9</td><td>9.322e-36j</td></tr>
<tr><td>080</td><td>32.3e+18</td><td>.876j</td></tr>
<tr><td>-0490</td><td>-90.</td><td>-.6545+0J</td></tr>
<tr><td>-0x260</td><td>-32.54e100</td><td>3e+26J</td></tr>
<tr><td>0x69</td><td>70.2E-12</td><td>4.53e-7j</td></tr>
</tbody></table>
<p>Python 还支持复数，复数由实数部分和虚数部分构成，可以用 <span class="marked">a + bj</span>，或者 <span class="marked">complex(a,b)</span> 表示， 复数的实部 <strong>a</strong> 和虚部 <strong>b</strong> 都是浮点型。</p>
<hr>
<h2>String（字符串）</h2>
<p>Python中的字符串用单引号 <span class="marked">'</span> 或双引号 <span class="marked">"</span> 括起来，同时使用反斜杠 <span class="marked">\</span> 转义特殊字符。</p>
<p>字符串的截取的语法格式如下：</p> <pre>变量[头下标:尾下标]</pre><p>索引值以 0 为开始值，-1 为从末尾的开始位置。</p>
<p><img decoding="async" src="https://static.runoob.com/wp-content/uploads/123456-20200923-1.svg"></p>
<p>加号  <span class="marked">+</span>  是字符串的连接符， 星号  <span class="marked">*</span>  表示复制当前字符串，与之结合的数字为复制的次数。实例如下：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: #a50">#!/usr/bin/python3</span><br />
<br />
<span style="color: Teal;">str</span> <span style="color: Gray;">=</span> <span style="color: #a11;">'Runoob'</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">str</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 输出字符串</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">str</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span>:-<span style="color: Maroon;">1</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp;<span style="color: #a50"># 输出第一个到倒数第二个的所有字符</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">str</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; <span style="color: #a50"># 输出字符串第一个字符</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">str</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">2</span>:<span style="color: Maroon;">5</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; <span style="color: #a50"># 输出从第三个开始到第五个的字符</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">str</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">2</span>:<span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 输出从第三个开始的后的所有字符</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">str</span> * <span style="color: Maroon;">2</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 输出字符串两次，也可以写成 print (2 * str) </span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">str</span> + <span style="color: #a11;">&quot;TEST&quot;</span><span style="color: Olive;">&#41;</span> <span style="color: #a50"># 连接字符串</span><br />

</div>
</div>
<p>执行以上程序会输出如下结果：</p>
<pre>
Runoob
Runoo
R
noo
noob
RunoobRunoob
RunoobTEST
</pre>
<p>Python 使用反斜杠 <span class="marked">\</span> 转义特殊字符，如果你不想让反斜杠发生转义，可以在字符串前面添加一个 <span class="marked">r</span>，表示原始字符串：</p>
<div class="example"><h2 class="example">实例</h2> <div class="example_code">
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">'Ru<span style="color: #000099; font-weight: bold;">\n</span>oob'</span><span style="color: Olive;">&#41;</span><br />
Ru<br />
oob<br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>r<span style="color: #a11;">'Ru<span style="color: #000099; font-weight: bold;">\n</span>oob'</span><span style="color: Olive;">&#41;</span><br />
Ru\noob<br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <br />
</div></div>

<p>
另外，反斜杠(\)可以作为续行符，表示下一行是上一行的延续。也可以使用 <b>"""..."""</b> 或者 <b>'''...'''</b> 跨越多行。
</p>


<p>注意，Python 没有单独的字符类型，一个字符就是长度为1的字符串。
</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: Gray;">&gt;&gt;&gt;</span> word <span style="color: Gray;">=</span> <span style="color: #a11;">'Python'</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>word<span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span><span style="color: Olive;">&#93;</span><span style="color: Gray;">,</span> word<span style="color: Olive;">&#91;</span><span style="color: Maroon;">5</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span><br />
P n<br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>word<span style="color: Olive;">&#91;</span>-<span style="color: Maroon;">1</span><span style="color: Olive;">&#93;</span><span style="color: Gray;">,</span> word<span style="color: Olive;">&#91;</span>-<span style="color: Maroon;">6</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span><br />
n P<br />

</div>
</div>


<p>与 C 字符串不同的是，Python 字符串不能被改变。向一个索引位置赋值，比如 <span class="marked">word[0] = 'm'</span> 会导致错误。
</p>
<p>
<b>注意：</b></p>
<ul>
<li>
1、反斜杠可以用来转义，使用r可以让反斜杠不发生转义。</li><li>
2、字符串可以用+运算符连接在一起，用*运算符重复。</li><li>
3、Python中的字符串有两种索引方式，从左往右以0开始，从右往左以-1开始。</li><li>
4、Python中的字符串不能改变。</li></ul><hr>
<h2>bool（布尔类型）</h2>
<p>布尔类型即 True 或 False。</p><p>在 Python 中，True 和 False 都是关键字，表示布尔值。</p>
<p>布尔类型可以用来控制程序的流程，比如判断某个条件是否成立，或者在某个条件满足时执行某段代码。</p>
<p>布尔类型特点：</p>
<ul><li><p>布尔类型只有两个值：True 和 False。</p></li><li><p>布尔类型可以和其他数据类型进行比较，比如数字、字符串等。在比较时，Python 会将 True 视为 1，False 视为 0。</p></li><li><p>布尔类型可以和逻辑运算符一起使用，包括 and、or 和 not。这些运算符可以用来组合多个布尔表达式，生成一个新的布尔值。</p></li><li><p>布尔类型也可以被转换成其他数据类型，比如整数、浮点数和字符串。在转换时，True 会被转换成 1，False 会被转换成 0。</p></li></ul>

<div class="example"><h2 class="example">实例</h2> <div class="example_code">
a <span style="color: Gray;">=</span> <span style="color: Teal;">True</span><br />
b <span style="color: Gray;">=</span> <span style="color: Teal;">False</span><br />
<br />
<span style="color: #a50"># 比较运算符</span><br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: Maroon;">2</span> <span style="color: Gray;">&lt;</span> <span style="color: Maroon;">3</span><span style="color: Olive;">&#41;</span> &nbsp; <span style="color: #a50"># True</span><br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: Maroon;">2</span> <span style="color: Gray;">==</span> <span style="color: Maroon;">3</span><span style="color: Olive;">&#41;</span> &nbsp;<span style="color: #a50"># False</span><br />
<br />
<span style="color: #a50"># 逻辑运算符</span><br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>a <span style="color: Green;font-weight:bold;">and</span> b<span style="color: Olive;">&#41;</span> &nbsp;<span style="color: #a50"># False</span><br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>a <span style="color: Green;font-weight:bold;">or</span> b<span style="color: Olive;">&#41;</span> &nbsp; <span style="color: #a50"># True</span><br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: Green;font-weight:bold;">not</span> a<span style="color: Olive;">&#41;</span> &nbsp; &nbsp;<span style="color: #a50"># False</span><br />
<br />
<span style="color: #a50"># 类型转换</span><br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: Teal;">int</span><span style="color: Olive;">&#40;</span>a<span style="color: Olive;">&#41;</span><span style="color: Olive;">&#41;</span> &nbsp; <span style="color: #a50"># 1</span><br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: Teal;">float</span><span style="color: Olive;">&#40;</span>b<span style="color: Olive;">&#41;</span><span style="color: Olive;">&#41;</span> <span style="color: #a50"># 0.0</span><br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: Teal;">str</span><span style="color: Olive;">&#40;</span>a<span style="color: Olive;">&#41;</span><span style="color: Olive;">&#41;</span> &nbsp; <span style="color: #a50"># &quot;True&quot;</span><br />
</div></div>
<p><strong>注意:</strong> 在 Python 中，所有非零的数字和非空的字符串、列表、元组等数据类型都被视为 True，只有 <strong>0、空字符串、空列表、空元组</strong>等被视为 False。因此，在进行布尔类型转换时，需要注意数据类型的真假性。</p>
<hr>
<h2>List（列表）</h2>
<p>List（列表） 是 Python 中使用最频繁的数据类型。</p>
<p>列表可以完成大多数集合类的数据结构实现。列表中元素的类型可以不相同，它支持数字，字符串甚至可以包含列表（所谓嵌套）。</p>
<p>列表是写在方括号 <span class="marked">[]</span> 之间、用逗号分隔开的元素列表。</p>
<p>
和字符串一样，列表同样可以被索引和截取，列表被截取后返回一个包含所需元素的新列表。
</p>
<p>列表截取的语法格式如下：</p> <pre>变量[头下标:尾下标]</pre><p>索引值以 <span class="marked">0</span> 为开始值，<span class="marked">-1</span> 为从末尾的开始位置。</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2014/08/list_slicing1_new1.png"></p>
<p>加号 <span class="marked">+</span> 是列表连接运算符，星号 <span class="marked">*</span> 是重复操作。如下实例：
</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: #a50">#!/usr/bin/python3</span><br />
<br />
<span style="color: Teal;">list</span> <span style="color: Gray;">=</span> <span style="color: Olive;">&#91;</span> <span style="color: #a11;">'abcd'</span><span style="color: Gray;">,</span> <span style="color: Maroon;">786</span> <span style="color: Gray;">,</span> <span style="color: Maroon;">2.23</span><span style="color: Gray;">,</span> <span style="color: #a11;">'runoob'</span><span style="color: Gray;">,</span> <span style="color: Maroon;">70.2</span> <span style="color: Olive;">&#93;</span><br />
tinylist <span style="color: Gray;">=</span> <span style="color: Olive;">&#91;</span><span style="color: Maroon;">123</span><span style="color: Gray;">,</span> <span style="color: #a11;">'runoob'</span><span style="color: Olive;">&#93;</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">list</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 输出完整列表</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">list</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a50"># 输出列表第一个元素</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">list</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">1</span>:<span style="color: Maroon;">3</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; <span style="color: #a50"># 从第二个开始输出到第三个元素</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">list</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">2</span>:<span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 输出从第三个元素开始的所有元素</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span>tinylist * <span style="color: Maroon;">2</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp;<span style="color: #a50"># 输出两次列表</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">list</span> + tinylist<span style="color: Olive;">&#41;</span> <span style="color: #a50"># 连接列表</span><br />

</div>
</div>
<p>以上实例输出结果：</p>
<pre>
['abcd', 786, 2.23, 'runoob', 70.2]
abcd
[786, 2.23]
[2.23, 'runoob', 70.2]
[123, 'runoob', 123, 'runoob']
['abcd', 786, 2.23, 'runoob', 70.2, 123, 'runoob']
</pre>

<p>与Python字符串不一样的是，列表中的元素是可以改变的：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: Gray;">&gt;&gt;&gt;</span> a <span style="color: Gray;">=</span> <span style="color: Olive;">&#91;</span><span style="color: Maroon;">1</span><span style="color: Gray;">,</span> <span style="color: Maroon;">2</span><span style="color: Gray;">,</span> <span style="color: Maroon;">3</span><span style="color: Gray;">,</span> <span style="color: Maroon;">4</span><span style="color: Gray;">,</span> <span style="color: Maroon;">5</span><span style="color: Gray;">,</span> <span style="color: Maroon;">6</span><span style="color: Olive;">&#93;</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> a<span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span><span style="color: Olive;">&#93;</span> <span style="color: Gray;">=</span> <span style="color: Maroon;">9</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> a<span style="color: Olive;">&#91;</span><span style="color: Maroon;">2</span>:<span style="color: Maroon;">5</span><span style="color: Olive;">&#93;</span> <span style="color: Gray;">=</span> <span style="color: Olive;">&#91;</span><span style="color: Maroon;">13</span><span style="color: Gray;">,</span> <span style="color: Maroon;">14</span><span style="color: Gray;">,</span> <span style="color: Maroon;">15</span><span style="color: Olive;">&#93;</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> a<br />
<span style="color: Olive;">&#91;</span><span style="color: Maroon;">9</span><span style="color: Gray;">,</span> <span style="color: Maroon;">2</span><span style="color: Gray;">,</span> <span style="color: Maroon;">13</span><span style="color: Gray;">,</span> <span style="color: Maroon;">14</span><span style="color: Gray;">,</span> <span style="color: Maroon;">15</span><span style="color: Gray;">,</span> <span style="color: Maroon;">6</span><span style="color: Olive;">&#93;</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> a<span style="color: Olive;">&#91;</span><span style="color: Maroon;">2</span>:<span style="color: Maroon;">5</span><span style="color: Olive;">&#93;</span> <span style="color: Gray;">=</span> <span style="color: Olive;">&#91;</span><span style="color: Olive;">&#93;</span> &nbsp; <span style="color: #a50"># 将对应的元素值设置为 [] </span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> a<br />
<span style="color: Olive;">&#91;</span><span style="color: Maroon;">9</span><span style="color: Gray;">,</span> <span style="color: Maroon;">2</span><span style="color: Gray;">,</span> <span style="color: Maroon;">6</span><span style="color: Olive;">&#93;</span><br />

</div>
</div>
<p>List 内置了有很多方法，例如 append()、pop() 等等，这在后面会讲到。</p>
<p><b>注意：</b></p>
<ul><li>
1、List写在方括号之间，元素用逗号隔开。</li><li>
2、和字符串一样，list可以被索引和切片。</li><li>
3、List可以使用+操作符进行拼接。</li><li>
4、List中的元素是可以改变的。</li>
</ul>
<p>Python 列表截取可以接收第三个参数，参数作用是截取的步长，以下实例在索引 1 到索引 4 的位置并设置为步长为 2（间隔一个位置）来截取字符串：</p>
<p><img decoding="async" src="https://www.runoob.com/wp-content/uploads/2014/08/py-dict-1.png"></p>

<p>如果第三个参数为负数表示逆向读取，以下实例用于翻转字符串：</p>
<div class="example"><h2 class="example">实例</h2> <div class="example_code">
<span style="color: Green;font-weight:bold;">def</span> reverseWords<span style="color: Olive;">&#40;</span><span style="color: Teal;">input</span><span style="color: Olive;">&#41;</span>: <br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a50"># 通过空格将字符串分隔符，把各个单词分隔为列表</span><br />
&nbsp; &nbsp; inputWords <span style="color: Gray;">=</span> <span style="color: Teal;">input</span>.<span style="color: #05a;">split</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">&quot; &quot;</span><span style="color: Olive;">&#41;</span> <br />
&nbsp; <br />
&nbsp; &nbsp; <span style="color: #a50"># 翻转字符串</span><br />
&nbsp; &nbsp; <span style="color: #a50"># 假设列表 list = [1,2,3,4], &nbsp;</span><br />
&nbsp; &nbsp; <span style="color: #a50"># list[0]=1, list[1]=2 ，而 -1 表示最后一个元素 list[-1]=4 ( 与 list[3]=4 一样) </span><br />
&nbsp; &nbsp; <span style="color: #a50"># inputWords[-1::-1] 有三个参数</span><br />
&nbsp; &nbsp; <span style="color: #a50"># 第一个参数 -1 表示最后一个元素</span><br />
&nbsp; &nbsp; <span style="color: #a50"># 第二个参数为空，表示移动到列表末尾</span><br />
&nbsp; &nbsp; <span style="color: #a50"># 第三个参数为步长，-1 表示逆向</span><br />
&nbsp; &nbsp; inputWords<span style="color: Gray;">=</span>inputWords<span style="color: Olive;">&#91;</span>-<span style="color: Maroon;">1</span>::-<span style="color: Maroon;">1</span><span style="color: Olive;">&#93;</span> <br />
&nbsp; <br />
&nbsp; &nbsp; <span style="color: #a50"># 重新组合字符串</span><br />
&nbsp; &nbsp; output <span style="color: Gray;">=</span> <span style="color: #a11;">' '</span>.<span style="color: #05a;">join</span><span style="color: Olive;">&#40;</span>inputWords<span style="color: Olive;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: Green;font-weight:bold;">return</span> output <br />
&nbsp; <br />
<span style="color: Green;font-weight:bold;">if</span> __name__ <span style="color: Gray;">==</span> <span style="color: #a11;">&quot;__main__&quot;</span>: <br />
&nbsp; &nbsp; <span style="color: Teal;">input</span> <span style="color: Gray;">=</span> <span style="color: #a11;">'I like runoob'</span><br />
&nbsp; &nbsp; rw <span style="color: Gray;">=</span> reverseWords<span style="color: Olive;">&#40;</span><span style="color: Teal;">input</span><span style="color: Olive;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>rw<span style="color: Olive;">&#41;</span><br />
</div></div>
<p>输出结果为：</p>
<pre>runoob like I</pre>
<hr><h2>Tuple（元组）</h2>
<p>元组（tuple）与列表类似，不同之处在于元组的元素不能修改。元组写在小括号 <span class="marked">()</span> 里，元素之间用逗号隔开。
</p><p>元组中的元素类型也可以不相同：
</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: #a50">#!/usr/bin/python3</span><br />
<br />
<span style="color: Teal;">tuple</span> <span style="color: Gray;">=</span> <span style="color: Olive;">&#40;</span> <span style="color: #a11;">'abcd'</span><span style="color: Gray;">,</span> <span style="color: Maroon;">786</span> <span style="color: Gray;">,</span> <span style="color: Maroon;">2.23</span><span style="color: Gray;">,</span> <span style="color: #a11;">'runoob'</span><span style="color: Gray;">,</span> <span style="color: Maroon;">70.2</span> &nbsp;<span style="color: Olive;">&#41;</span><br />
tinytuple <span style="color: Gray;">=</span> <span style="color: Olive;">&#40;</span><span style="color: Maroon;">123</span><span style="color: Gray;">,</span> <span style="color: #a11;">'runoob'</span><span style="color: Olive;">&#41;</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">tuple</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a50"># 输出完整元组</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">tuple</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 输出元组的第一个元素</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">tuple</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">1</span>:<span style="color: Maroon;">3</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 输出从第二个元素开始到第三个元素</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">tuple</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">2</span>:<span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a50"># 输出从第三个元素开始的所有元素</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span>tinytuple * <span style="color: Maroon;">2</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; <span style="color: #a50"># 输出两次元组</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">tuple</span> + tinytuple<span style="color: Olive;">&#41;</span> <span style="color: #a50"># 连接元组</span><br />

</div>
</div>
<p>以上实例输出结果：</p>
<pre>
('abcd', 786, 2.23, 'runoob', 70.2)
abcd
(786, 2.23)
(2.23, 'runoob', 70.2)
(123, 'runoob', 123, 'runoob')
('abcd', 786, 2.23, 'runoob', 70.2, 123, 'runoob')
</pre>
<p>元组与字符串类似，可以被索引且下标索引从0开始，-1 为从末尾开始的位置。也可以进行截取（看上面，这里不再赘述）。</p>
<p>其实，可以把字符串看作一种特殊的元组。
</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: Gray;">&gt;&gt;&gt;</span> tup <span style="color: Gray;">=</span> <span style="color: Olive;">&#40;</span><span style="color: Maroon;">1</span><span style="color: Gray;">,</span> <span style="color: Maroon;">2</span><span style="color: Gray;">,</span> <span style="color: Maroon;">3</span><span style="color: Gray;">,</span> <span style="color: Maroon;">4</span><span style="color: Gray;">,</span> <span style="color: Maroon;">5</span><span style="color: Gray;">,</span> <span style="color: Maroon;">6</span><span style="color: Olive;">&#41;</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>tup<span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span><br />
<span style="color: Maroon;">1</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>tup<span style="color: Olive;">&#91;</span><span style="color: Maroon;">1</span>:<span style="color: Maroon;">5</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span><br />
<span style="color: Olive;">&#40;</span><span style="color: Maroon;">2</span><span style="color: Gray;">,</span> <span style="color: Maroon;">3</span><span style="color: Gray;">,</span> <span style="color: Maroon;">4</span><span style="color: Gray;">,</span> <span style="color: Maroon;">5</span><span style="color: Olive;">&#41;</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> tup<span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span><span style="color: Olive;">&#93;</span> <span style="color: Gray;">=</span> <span style="color: Maroon;">11</span> &nbsp;<span style="color: #a50"># 修改元组元素的操作是非法的</span><br />
Traceback <span style="color: Olive;">&#40;</span>most recent call last<span style="color: Olive;">&#41;</span>:<br />
&nbsp; File <span style="color: #a11;">&quot;&lt;stdin&gt;&quot;</span><span style="color: Gray;">,</span> line <span style="color: Maroon;">1</span><span style="color: Gray;">,</span> <span style="color: Green;font-weight:bold;">in</span> <span style="color: Gray;">&lt;</span>module<span style="color: Gray;">&gt;</span><br />
<span style="color: Teal;">TypeError</span>: <span style="color: #a11;">'tuple'</span> <span style="color: Teal;">object</span> does <span style="color: Green;font-weight:bold;">not</span> support item assignment<br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <br />

</div>
</div>
<p>虽然tuple的元素不可改变，但它可以包含可变的对象，比如list列表。
</p><p>
构造包含 0 个或 1 个元素的元组比较特殊，所以有一些额外的语法规则：
</p>
<pre>
tup1 = ()    # 空元组
tup2 = (20,) # 一个元素，需要在元素后添加逗号
</pre>

<p>string、list 和 tuple 都属于 sequence（序列）。</p>
<p><b>注意：</b></p>
<ul><li>
1、与字符串一样，元组的元素不能修改。</li><li>
2、元组也可以被索引和切片，方法一样。</li><li>
3、注意构造包含 0 或 1 个元素的元组的特殊语法规则。</li><li>
4、元组也可以使用+操作符进行拼接。</li></ul>
<hr><h2>Set（集合）</h2>
<p>
集合（set）是由一个或数个形态各异的大小整体组成的，构成集合的事物或对象称作元素或是成员。</p>
<p>基本功能是进行成员关系测试和删除重复元素。</p>
<p>可以使用大括号 <span class="marked">{ }</span> 或者 <span class="marked">set()</span> 函数创建集合，注意：创建一个空集合必须用<span class="marked"> set()</span> 而不是 <span class="marked">{ }</span>，因为 <span class="marked">{ }</span> 是用来创建一个空字典。
</p>
<p>创建格式：</p>
<pre>parame = {value01,value02,...}
或者
set(value)</pre>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: #a50">#!/usr/bin/python3</span><br />
<br />
sites <span style="color: Gray;">=</span> <span style="color: Olive;">&#123;</span><span style="color: #a11;">'Google'</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Taobao'</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Runoob'</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Facebook'</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Zhihu'</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Baidu'</span><span style="color: Olive;">&#125;</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>sites<span style="color: Olive;">&#41;</span> &nbsp; <span style="color: #a50"># 输出集合，重复的元素被自动去掉</span><br />
<br />
<span style="color: #a50"># 成员测试</span><br />
<span style="color: Green;font-weight:bold;">if</span> <span style="color: #a11;">'Runoob'</span> <span style="color: Green;font-weight:bold;">in</span> sites :<br />
&nbsp; &nbsp; <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">'Runoob 在集合中'</span><span style="color: Olive;">&#41;</span><br />
<span style="color: Green;font-weight:bold;">else</span> :<br />
&nbsp; &nbsp; <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">'Runoob 不在集合中'</span><span style="color: Olive;">&#41;</span><br />
<br />
<br />
<span style="color: #a50"># set可以进行集合运算</span><br />
a <span style="color: Gray;">=</span> <span style="color: Teal;">set</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">'abracadabra'</span><span style="color: Olive;">&#41;</span><br />
b <span style="color: Gray;">=</span> <span style="color: Teal;">set</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">'alacazam'</span><span style="color: Olive;">&#41;</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>a<span style="color: Olive;">&#41;</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>a - b<span style="color: Olive;">&#41;</span> &nbsp; &nbsp; <span style="color: #a50"># a 和 b 的差集</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>a | b<span style="color: Olive;">&#41;</span> &nbsp; &nbsp; <span style="color: #a50"># a 和 b 的并集</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>a &amp; b<span style="color: Olive;">&#41;</span> &nbsp; &nbsp; <span style="color: #a50"># a 和 b 的交集</span><br />
<br />
<span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span>a ^ b<span style="color: Olive;">&#41;</span> &nbsp; &nbsp; <span style="color: #a50"># a 和 b 中不同时存在的元素</span><br />

</div>
</div>
<p>以上实例输出结果：</p>
<pre>
{'Zhihu', 'Baidu', 'Taobao', 'Runoob', 'Google', 'Facebook'}
Runoob 在集合中
{'b', 'c', 'a', 'r', 'd'}
{'r', 'b', 'd'}
{'b', 'c', 'a', 'z', 'm', 'r', 'l', 'd'}
{'c', 'a'}
{'z', 'b', 'm', 'r', 'l', 'd'}
</pre>
<hr><h2>Dictionary（字典）</h2>
<p>
字典（dictionary）是Python中另一个非常有用的内置数据类型。</p>
<p>列表是有序的对象集合，字典是无序的对象集合。两者之间的区别在于：字典当中的元素是通过键来存取的，而不是通过偏移存取。</p>
<p>字典是一种映射类型，字典用 <span class="marked">{ }</span> 标识，它是一个无序的 <b>键(key) : 值(value)</b> 的集合。</p>
<p>键(key)必须使用不可变类型。</p>
<p>在同一个字典中，键(key)必须是唯一的。
</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: #a50">#!/usr/bin/python3</span><br />
<br />
<span style="color: Teal;">dict</span> <span style="color: Gray;">=</span> <span style="color: Olive;">&#123;</span><span style="color: Olive;">&#125;</span><br />
<span style="color: Teal;">dict</span><span style="color: Olive;">&#91;</span><span style="color: #a11;">'one'</span><span style="color: Olive;">&#93;</span> <span style="color: Gray;">=</span> <span style="color: #a11;">&quot;1 - 菜鸟教程&quot;</span><br />
<span style="color: Teal;">dict</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">2</span><span style="color: Olive;">&#93;</span> &nbsp; &nbsp; <span style="color: Gray;">=</span> <span style="color: #a11;">&quot;2 - 菜鸟工具&quot;</span><br />
<br />
tinydict <span style="color: Gray;">=</span> <span style="color: Olive;">&#123;</span><span style="color: #a11;">'name'</span>: <span style="color: #a11;">'runoob'</span><span style="color: Gray;">,</span><span style="color: #a11;">'code'</span>:<span style="color: Maroon;">1</span><span style="color: Gray;">,</span> <span style="color: #a11;">'site'</span>: <span style="color: #a11;">'www.runoob.com'</span><span style="color: Olive;">&#125;</span><br />
<br />
<br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">dict</span><span style="color: Olive;">&#91;</span><span style="color: #a11;">'one'</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; <span style="color: #a50"># 输出键为 'one' 的值</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span><span style="color: Teal;">dict</span><span style="color: Olive;">&#91;</span><span style="color: Maroon;">2</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a50"># 输出键为 2 的值</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span>tinydict<span style="color: Olive;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #a50"># 输出完整的字典</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span>tinydict.<span style="color: #05a;">keys</span><span style="color: Olive;">&#40;</span><span style="color: Olive;">&#41;</span><span style="color: Olive;">&#41;</span> &nbsp; <span style="color: #a50"># 输出所有键</span><br />
<span style="color: Green;font-weight:bold;">print</span> <span style="color: Olive;">&#40;</span>tinydict.<span style="color: #05a;">values</span><span style="color: Olive;">&#40;</span><span style="color: Olive;">&#41;</span><span style="color: Olive;">&#41;</span> <span style="color: #a50"># 输出所有值</span><br />

</div>
</div>
<p>以上实例输出结果：</p>
<pre>
1 - 菜鸟教程
2 - 菜鸟工具
{'name': 'runoob', 'code': 1, 'site': 'www.runoob.com'}
dict_keys(['name', 'code', 'site'])
dict_values(['runoob', 1, 'www.runoob.com'])
</pre>
<p>构造函数 dict() 可以直接从键值对序列中构建字典如下：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">

<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Teal;">dict</span><span style="color: Olive;">&#40;</span><span style="color: Olive;">&#91;</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">'Runoob'</span><span style="color: Gray;">,</span> <span style="color: Maroon;">1</span><span style="color: Olive;">&#41;</span><span style="color: Gray;">,</span> <span style="color: Olive;">&#40;</span><span style="color: #a11;">'Google'</span><span style="color: Gray;">,</span> <span style="color: Maroon;">2</span><span style="color: Olive;">&#41;</span><span style="color: Gray;">,</span> <span style="color: Olive;">&#40;</span><span style="color: #a11;">'Taobao'</span><span style="color: Gray;">,</span> <span style="color: Maroon;">3</span><span style="color: Olive;">&#41;</span><span style="color: Olive;">&#93;</span><span style="color: Olive;">&#41;</span><br />
<span style="color: Olive;">&#123;</span><span style="color: #a11;">'Runoob'</span>: <span style="color: Maroon;">1</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Google'</span>: <span style="color: Maroon;">2</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Taobao'</span>: <span style="color: Maroon;">3</span><span style="color: Olive;">&#125;</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Olive;">&#123;</span>x: x**<span style="color: Maroon;">2</span> <span style="color: Green;font-weight:bold;">for</span> x <span style="color: Green;font-weight:bold;">in</span> <span style="color: Olive;">&#40;</span><span style="color: Maroon;">2</span><span style="color: Gray;">,</span> <span style="color: Maroon;">4</span><span style="color: Gray;">,</span> <span style="color: Maroon;">6</span><span style="color: Olive;">&#41;</span><span style="color: Olive;">&#125;</span><br />
<span style="color: Olive;">&#123;</span><span style="color: Maroon;">2</span>: <span style="color: Maroon;">4</span><span style="color: Gray;">,</span> <span style="color: Maroon;">4</span>: <span style="color: Maroon;">16</span><span style="color: Gray;">,</span> <span style="color: Maroon;">6</span>: <span style="color: Maroon;">36</span><span style="color: Olive;">&#125;</span><br />
<span style="color: Gray;">&gt;&gt;&gt;</span> <span style="color: Teal;">dict</span><span style="color: Olive;">&#40;</span>Runoob<span style="color: Gray;">=</span><span style="color: Maroon;">1</span><span style="color: Gray;">,</span> Google<span style="color: Gray;">=</span><span style="color: Maroon;">2</span><span style="color: Gray;">,</span> Taobao<span style="color: Gray;">=</span><span style="color: Maroon;">3</span><span style="color: Olive;">&#41;</span><br />
<span style="color: Olive;">&#123;</span><span style="color: #a11;">'Runoob'</span>: <span style="color: Maroon;">1</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Google'</span>: <span style="color: Maroon;">2</span><span style="color: Gray;">,</span> <span style="color: #a11;">'Taobao'</span>: <span style="color: Maroon;">3</span><span style="color: Olive;">&#125;</span><br />

</div>
</div>

<p><span class="marked">{x: x**2 for x in (2, 4, 6)}</span> 该代码使用的是字典推导式，更多推导式内容可以参考：<a href="../python3/python-comprehensions.html" rel="noopener" target="_blank">Python 推导式</a>。</p>
<p>另外，字典类型也有一些内置的函数，例如 clear()、keys()、values() 等。</p>
<p><b>注意：</b></p>
<ul><li>
1、字典是一种映射类型，它的元素是键值对。</li><li>
2、字典的关键字必须为不可变类型，且不能重复。</li><li>
3、创建空字典使用 <b>{ }</b>。</li></ul><hr>
<h2>bytes 类型</h2>

<p>在 Python3 中，bytes 类型表示的是不可变的二进制序列（byte sequence）。</p><p>与字符串类型不同的是，bytes 类型中的元素是整数值（0 到 255 之间的整数），而不是 Unicode 字符。</p>
<p>
bytes 类型通常用于处理二进制数据，比如图像文件、音频文件、视频文件等等。在网络编程中，也经常使用 bytes 类型来传输二进制数据。</p>
<p>
创建 bytes 对象的方式有多种，最常见的方式是使用 b 前缀：</p>
<p>
此外，也可以使用 bytes() 函数将其他类型的对象转换为 bytes 类型。bytes() 函数的第一个参数是要转换的对象，第二个参数是编码方式，如果省略第二个参数，则默认使用 UTF-8 编码：</p>
<pre>x = bytes("hello", encoding="utf-8")</pre><p>
与字符串类型类似，bytes 类型也支持许多操作和方法，如切片、拼接、查找、替换等等。同时，由于 bytes 类型是不可变的，因此在进行修改操作时需要创建一个新的 bytes 对象。例如：</p>
<div class="example"><h2 class="example">实例</h2> <div class="example_code">
<br />
x <span style="color: Gray;">=</span> b<span style="color: #a11;">&quot;hello&quot;</span><br />
y <span style="color: Gray;">=</span> x<span style="color: Olive;">&#91;</span><span style="color: Maroon;">1</span>:<span style="color: Maroon;">3</span><span style="color: Olive;">&#93;</span> &nbsp;<span style="color: #a50"># 切片操作，得到 b&quot;el&quot;</span><br />
z <span style="color: Gray;">=</span> x + b<span style="color: #a11;">&quot;world&quot;</span> &nbsp;<span style="color: #a50"># 拼接操作，得到 b&quot;helloworld&quot;</span><br />
</div></div>
<p>需要注意的是，bytes 类型中的元素是整数值，因此在进行比较操作时需要使用相应的整数值。例如：</p>
<div class="example"><h2 class="example">实例</h2> <div class="example_code">
x <span style="color: Gray;">=</span> b<span style="color: #a11;">&quot;hello&quot;</span><br />
<span style="color: Green;font-weight:bold;">if</span> x<span style="color: Olive;">&#91;</span><span style="color: Maroon;">0</span><span style="color: Olive;">&#93;</span> <span style="color: Gray;">==</span> <span style="color: Teal;">ord</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">&quot;h&quot;</span><span style="color: Olive;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: Green;font-weight:bold;">print</span><span style="color: Olive;">&#40;</span><span style="color: #a11;">&quot;The first element is 'h'&quot;</span><span style="color: Olive;">&#41;</span><br />
</div></div>
<p>其中 ord() 函数用于将字符转换为相应的整数值。</p>
<hr>
<h2>Python数据类型转换</h2>
<p>
有时候，我们需要对数据内置的类型进行转换，数据类型的转换，你只需要将数据类型作为函数名即可，在下一章节 <a href="../python3/python3-type-conversion.html" rel="noopener" target="_blank">Python3 数据类型转换</a> 会具体介绍。</p>
<p>
以下几个内置的函数可以执行数据类型之间的转换。这些函数返回一个新的对象，表示转换的值。</p>
<table class="reference">
<tbody><tr><th>函数</th><th>描述</th></tr>
<tr valign="top">
<td>
<p><a href="python-func-int.html" target="_blank" rel="noopener noreferrer">int(x [,base])</a></p>
</td>
<td>
<p>将x转换为一个整数</p>
</td>
</tr>

<tr valign="top">
<td>
<p><a href="python-func-float.html" target="_blank" rel="noopener noreferrer">float(x)</a></p>
</td>
<td>
<p>将x转换到一个浮点数</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-complex.html" target="_blank" rel="noopener noreferrer">complex(real [,imag])</a></p>
</td>
<td>
<p>创建一个复数</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-str.html" target="_blank" rel="noopener noreferrer">str(x)</a></p>
</td>
<td>
<p>将对象 x 转换为字符串</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-repr.html" target="_blank" rel="noopener noreferrer">repr(x)</a></p>
</td>
<td>
<p>将对象 x 转换为表达式字符串</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-eval.html" target="_blank" rel="noopener noreferrer">eval(str)</a></p>
</td>
<td>
<p>用来计算在字符串中的有效Python表达式,并返回一个对象</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="../python3/python3-func-tuple.html" target="_blank" rel="noopener noreferrer">tuple(s)</a></p>
</td>
<td>
<p>将序列 s 转换为一个元组</p>

</td>
</tr>
<tr valign="top">
<td>
<p><a href="python3-att-list-list.html" target="_blank" rel="noopener noreferrer">list(s)</a></p>
</td>
<td>
<p>将序列 s 转换为一个列表</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-set.html" target="_blank" rel="noopener noreferrer">set(s)</a></p>
</td>
<td>
<p>转换为可变集合</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-dict.html" target="_blank" rel="noopener noreferrer">dict(d)</a></p>
</td>
<td>
<p>创建一个字典。d 必须是一个 (key, value)元组序列。</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-frozenset.html" target="_blank" rel="noopener noreferrer">frozenset(s)</a></p>
</td>
<td>
<p>转换为不可变集合</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-chr.html" target="_blank" rel="noopener noreferrer">chr(x)</a></p>
</td>
<td>
<p>  将一个整数转换为一个字符</p>
</td>
</tr>

<tr valign="top">
<td>
<p><a href="python-func-ord.html" target="_blank" rel="noopener noreferrer">ord(x)</a></p>
</td>
<td>
<p> 将一个字符转换为它的整数值</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-hex.html" target="_blank" rel="noopener noreferrer">hex(x)</a></p>
</td>
<td>
<p>  将一个整数转换为一个十六进制字符串</p>
</td>
</tr>
<tr valign="top">
<td>
<p><a href="python-func-oct.html" target="_blank" rel="noopener noreferrer">oct(x)</a></p>
</td>
<td>
<p> 将一个整数转换为一个八进制字符串</p>
</td>
</tr>
</tbody></table>			<!-- 其他扩展 -->
						
			</div>
			
		</div>
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../python3/python3-basic-syntax.html" rel="prev"> Python3 基础语法</a> </div>
			<div class="next-design-link"><a href="../python3/python3-examples.html" rel="next"> Python3 实例</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
		<!-- 笔记列表 -->
		<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div class="title" id="comments">
	<h2 class="">
    <div class="altblock">
				<i style="font-size:28px;margin-top: 8px;" class="fa fa-plus-square" aria-hidden="true"></i>
		    </div>
    <span class="mw-headline" id="qa_headline">20  篇笔记</span>
	<span class="mw-headline" id="user_add_note" style="float:right;line-height: 62px;padding-right: 14px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  写笔记</span>
    </h2>
</div>

<div id="postcomments"  style="display:none;" >
	<ol class="commentlist">
		<li class="comment even thread-even depth-1" id="comment-11702"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;荆棘乱</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;llc***n@gmail.com</p></div><div id="runoobvote-id-11702" data-commid = "11702" class="upvotejs"><a class="upvote"></a> <span class="count">459</span></div></div><div class="comt-main" id="div-comment-11702"><h2>元组（小拓展）
</h2><p>
一般来说，函数的返回值一般为一个。
</p><p>
而函数返回多个值的时候，是以元组的方式返回的。
</p><p>
示例（命令行下）：
</p><pre>
&gt;&gt;&gt;def example(a,b):
...     return (a,b)
...
&gt;&gt;&gt;type(example(3,4))
&lt;class 'tuple'&gt;
&gt;&gt;&gt;</pre><p>
python中的函数还可以接收可变长参数，比如以 "*" 开头的的参数名，会将所有的参数收集到一个元组上。
</p><p>
例如：</p><pre>
def test(*args):
    print(args)
    return args

print(type(test(1,2,3,4)))    #可以看见其函数的返回值是一个元组
</pre><h2>
字典（小拓展）</h2>
<p>
python中的字典是使用了一个称为散列表（hashtable）的算法（不具体展开），
</p><p>
其特点就是：不管字典中有多少项，in操作符花费的时间都差不多。
</p><p>
如果把一个字典对象作为for的迭代对象，那么这个操作将会遍历字典的键：
</p><pre>
def example(d):
    # d 是一个字典对象
    for c in d:
        print(c)
        #如果调用函数试试的话，会发现函数会将d的所有键打印出来;
        #也就是遍历的是d的键，而不是值.</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">荆棘乱</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;荆棘乱</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;llc***n@gmail.com</p></div></span>6年前 (2017-05-05)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-13437"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;我去咬你啦</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;815***114@qq.com</p></div><div id="runoobvote-id-13437" data-commid = "13437" class="upvotejs"><a class="upvote"></a> <span class="count">253</span></div></div><div class="comt-main" id="div-comment-13437"><p>针对楼上的 字典 拓展，做测试的时候，想要输出 kye:value的组合发现可以这样：
</p><pre>
for c in dict:
    print(c,':',dict[c])
</pre><p>
或者</p>
<pre>
for c in dict:
    print(c,end=':');
    print(dict[c])
</pre><p>
于是发现 print()函数 其实可以 添加多个参数，用逗号 隔开。
</p><p>
本来想要用
</p><pre>
for c in dict:
    print(c+':');
    print(dict[c])
</pre>
<p>
这样的方式打印 key：value结果发现其实 key不一定是 string类型，所以 用+ 号会出问题。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">我去咬你啦</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;我去咬你啦</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;815***114@qq.com</p></div></span>6年前 (2017-06-28)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-13572"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;愤怒的胸毛毛</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;zha***aijun2013@foxmail.com</p></div><div id="runoobvote-id-13572" data-commid = "13572" class="upvotejs"><a class="upvote"></a> <span class="count">167</span></div></div><div class="comt-main" id="div-comment-13572"><p>在list的使用中，开始时很容易忽视的一点是：
</p><pre>
list = [ 'abcd', 786 , 2.23, 'runoob', 70.2 ]
print (list[1:3])       # 从第二个开始输出到第三个元素</pre><p>
list[1:3] 其实输出的只有两个变量，即list中第二个元素到第三个元素，并不是第1 第2 第3三个元素，而且要注意的是
</p><pre>
print (list[2])
print (list[2:3])</pre><p>
这两句话打印的内容其实是一样的，
</p><pre>
2.23
[2.23]</pre><p>
但是第二句话有中括号</p>
<p>------------------------------------------------------</p>
<p>以下是网友 <a href="mailto:temmple_wang@qq.com" rel="nofollow">temmple_wang@qq.com</a> 的补充：</p>

<pre>list = [ 'abcd', 786 , 2.23, 'runoob', 70.2 ]
print (list[1:3])       # 从第二个开始输出到第三个元素
# 获得结果 [786, 2.23]</pre>
<p>其实我觉得可以这样理解：</p>

<pre>print (list[1:3])       # 从数组下标为1的数开始获取直到数组下标为3（但不包含3）的数为止，输出这段
# 获得结果 [786, 2.23]
</pre>
<p>其实我们可以试验一下：</p>

<pre>print (list[1:0])       # 没有输出的值
# 获得结果 []

print (list[1:1])       # 没有输出的值
# 获得结果 []

print (list[0:1])       # 没有输出的值
# 获得结果 ['abcd']
</pre>
<p>其实中括号里的值还可以为负数：</p>

<pre>
&gt;&gt;&gt; print(arrtest[1:-1])    # 从下标为1的数开始，输出到下标为4但不包含4的所有值
[786, 2.23, 'runoob']
&gt;&gt;&gt; print(arrtest[-3:-2])   # 从下标为2的数开始，输出到下标为3但不包含3的所有值
[2.23]
</pre>
<p>----------------------------</p>
<p>list 补充:</p>

<pre>list = [ 'abcd', 786 , 2.23, 'runoob', 70.2 ]
print (list[2])
print (list[2:3])</pre>
<p>这两句话打印的内容其实是一样的:</p>

<pre>2.23
[2.23]</pre>
<p>但注意是不同的类型，用变量接收一下：</p>

<pre>a = list[2]
b = list[2:3]
type(a) -&gt; &lt;class 'float'&gt;
type(b) -&gt; &lt;class 'list'&gt;</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">愤怒的胸毛毛</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;愤怒的胸毛毛</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;zha***aijun2013@foxmail.com</p></div></span>6年前 (2017-07-02)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-13835"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;hellowqp</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;wqp***a@foxmail.com</p></div><div id="runoobvote-id-13835" data-commid = "13835" class="upvotejs"><a class="upvote"></a> <span class="count">83</span></div></div><div class="comt-main" id="div-comment-13835"><p>python 与 C 语言和 Java 语言的一点不同，表现在它的变量不需要声明变量类型，这是因为像 C 语言和 Java 语言来说，它们是静态的，而 python 是动态的，变量的类型由赋予它的值来决定，例如：</p><pre>&gt;&gt;&gt; a = 1
&gt;&gt;&gt; a = 1.001
&gt;&gt;&gt; a = "python"
&gt;&gt;&gt; print(a)
python
&gt;&gt;&gt; </pre><p>第一次为变量 a 赋值为整型，第二次赋值是浮点数，第三次是一个字符串，最后输出时只保留了最后一次的赋值。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">hellowqp</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;hellowqp</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;wqp***a@foxmail.com</p></div></span>6年前 (2017-07-08)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-17628"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;燕春</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;zqs***306010@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://blog.csdn.net/cn_wk/article/details/51314238">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-17628" data-commid = "17628" class="upvotejs"><a class="upvote"></a> <span class="count">75</span></div></div><div class="comt-main" id="div-comment-17628"><p>type 是用于求一个未知数据类型对象，而 isinstance 是用于判断一个对象是否是已知类型。</p>
<p>type 不认为子类是父类的一种类型，而isinstance会认为子类是父类的一种类型。</p>
<p>可以用 isinstance 判断子类对象是否继承于父类，type 不行。</p>
<p>综合以上几点，type 与 isinstance 虽然都与数据类型相关，但两者其实用法不同，type 主要用于判断未知数据类型，isinstance 主要用于判断 A 类是否继承于 B 类：</p>

<pre># 判断子类对象是否继承于父类
class father(object):
    pass
class son(father):
    pass
if __name__ == '__main__':
    print (type(son())==father)
    print (isinstance(son(),father))
    print (type(son()))
    print (type(son))</pre>

<p>运行结果：</p>
<pre>False
True
&lt;class '__main__.son'&gt;
&lt;type 'type'&gt;</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">燕春</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;燕春</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;zqs***306010@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://blog.csdn.net/cn_wk/article/details/51314238">&nbsp;&nbsp;参考地址</a></p></div></span>6年前 (2017-09-15)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-21310"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;妞妞</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;704***556@qq.com</p></div><div id="runoobvote-id-21310" data-commid = "21310" class="upvotejs"><a class="upvote"></a> <span class="count">113</span></div></div><div class="comt-main" id="div-comment-21310"><p><strong>字典（小拓展）</strong></p>

<p>输入 dict 的键值对，可直接用 <span class="marked">items()</span> 函数：</p>

<pre>dict1 = {'abc':1,"cde":2,"d":4,"c":567,"d":"key1"}
for k,v in dict1.items():
    print(k,":",v)</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">妞妞</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;妞妞</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;704***556@qq.com</p></div></span>5年前 (2017-12-07)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-21432"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;hjc132</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;huj***heng132@gmail.com</p></div><div id="runoobvote-id-21432" data-commid = "21432" class="upvotejs"><a class="upvote"></a> <span class="count">152</span></div></div><div class="comt-main" id="div-comment-21432"><p><strong>字典（小拓展）</strong></p>

<p>原文说 dict(d)创建一个字典。d 必须是一个序列 (key,value)元组。</p>

<p>其实d不一定必须为一个序列元组，如下：</p>

<pre>&gt;&gt;&gt; dict_1 = dict([('a',1),('b',2),('c',3)]) #元素为元组的列表
&gt;&gt;&gt; dict_1
{'a': 1, 'b': 2, 'c': 3}
&gt;&gt;&gt; dict_2 = dict({('a',1),('b',2),('c',3)})#元素为元组的集合
&gt;&gt;&gt; dict_2
{'b': 2, 'c': 3, 'a': 1}
&gt;&gt;&gt; dict_3 = dict([['a',1],['b',2],['c',3]])#元素为列表的列表
&gt;&gt;&gt; dict_3
{'a': 1, 'b': 2, 'c': 3}
&gt;&gt;&gt; dict_4 = dict((('a',1),('b',2),('c',3)))#元素为元组的元组
&gt;&gt;&gt; dict_4
{'a': 1, 'b': 2, 'c': 3}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">hjc132</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;hjc132</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;huj***heng132@gmail.com</p></div></span>5年前 (2017-12-10)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-24483"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;好好学习天天向上</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;522***154@qq.com</p></div><div id="runoobvote-id-24483" data-commid = "24483" class="upvotejs"><a class="upvote"></a> <span class="count">60</span></div></div><div class="comt-main" id="div-comment-24483"><p><strong>集合与字典</strong></p>

<p><strong>无序：</strong>集合是无序的，所以不支持索引；字典同样也是无序的，但由于其元素是由键（key）和值（value）两个属性组成的键值对，可以通过键（key）来进行索引</p>

<p><strong>元素唯一性：</strong>集合是无重复元素的序列，会自动去除重复元素；字典因为其key唯一性，所以也不会出现相同元素</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">好好学习天天向上</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;好好学习天天向上</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;522***154@qq.com</p></div></span>5年前 (2018-03-01)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-24865"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Lonapse</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;270***302@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://blog.csdn.net/henni_719/article/details/56665254">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-24865" data-commid = "24865" class="upvotejs"><a class="upvote"></a> <span class="count">42</span></div></div><div class="comt-main" id="div-comment-24865"><pre>#coding=utf8  
''''' 
复数是由一个实数和一个虚数组合构成，表示为：x+yj 
一个负数时一对有序浮点数(x,y)，其中x是实数部分，y是虚数部分。 
Python语言中有关负数的概念： 
1、虚数不能单独存在，它们总是和一个值为0.0的实数部分一起构成一个复数 
2、复数由实数部分和虚数部分构成 
3、表示虚数的语法：real+imagej 
4、实数部分和虚数部分都是浮点数 
5、虚数部分必须有后缀j或J 
 
复数的内建属性： 
复数对象拥有数据属性，分别为该复数的实部和虚部。 
复数还拥有conjugate方法，调用它可以返回该复数的共轭复数对象。 
复数属性：real(复数的实部)、imag(复数的虚部)、conjugate()（返回复数的共轭复数） 
'''  
class Complex(object):  
    '''''创建一个静态属性用来记录类版本号'''  
    version=1.0  
    '''''创建个复数类，用于操作和初始化复数'''  
    def __init__(self,rel=15,img=15j):  
        self.realPart=rel  
        self.imagPart=img  
         
    #创建复数  
    def creatComplex(self):  
        return self.realPart+self.imagPart  
    #获取输入数字部分的虚部  
    def getImg(self):  
        #把虚部转换成字符串  
        img=str(self.imagPart)  
        #对字符串进行切片操作获取数字部分  
        img=img[:-1]   
        return float(img)    
                         
def test():  
    print "run test..........."  
    com=Complex()  
    Cplex= com.creatComplex()  
    if Cplex.imag==com.getImg():  
        print com.getImg()  
    else:  
        pass  
    if Cplex.real==com.realPart:  
        print com.realPart  
    else:  
        pass  
    #原复数  
    print "the religion complex is :",Cplex  
    #求取共轭复数  
    print "the conjugate complex is :",Cplex.conjugate()  
      
if __name__=="__main__":  
    test()</pre>  <div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">Lonapse</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Lonapse</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;270***302@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://blog.csdn.net/henni_719/article/details/56665254">&nbsp;&nbsp;参考地址</a></p></div></span>5年前 (2018-03-11)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-28132"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;符号</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;974***897@QQ.com</p></div><div id="runoobvote-id-28132" data-commid = "28132" class="upvotejs"><a class="upvote"></a> <span class="count">29</span></div></div><div class="comt-main" id="div-comment-28132"><p data-title="python 切片步长">切片还可以设置步长</p>

<pre>
demo = [1,2,3,4,5,6]

new_demo = demo[1::2]  # 2 就是步长 意思是从索引为 1 的元素开始 每隔2个元素取一次元素
new_demo = [2,4,6] 

# 以索引为列  [索引] 和 [索引:索引:步长] 的区别
# demo[索引] 取出的原列表中索引对应的元素
# demo[索引:索引:步长] 切片得到的是一个新列表</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="../note/28132">符号</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;符号</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;974***897@QQ.com</p></div></span>5年前 (2018-06-06)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-30201"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;王二的弟弟</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;182***56065@163.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://blog.csdn.net/fei_gao/article/details/5914759">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-30201" data-commid = "30201" class="upvotejs"><a class="upvote"></a> <span class="count">48</span></div></div><div class="comt-main" id="div-comment-30201">
<p data-title="Python3 布尔(bool)类型详解"><strong>bool 型</strong></p>

<p>Python 中布尔值使用常量 <strong>True</strong> 和 <strong>False</strong> 来表示。</p>
<p>1、在数值上下文环境中，<strong>True</strong> 被当作 <strong>1</strong>，<strong>False</strong> 被当作 <strong>0</strong>，例如：</p>
<pre>&gt;&gt;&gt; True+3
4
&gt;&gt;&gt; False+2
2
</pre>

 

<p>2、其他类型值转换 <strong>bool</strong>  值时除了 <span class="marked">''、""、''''''、""""""、0、()、[]、{}、None、0.0、0L、0.0+0.0j、False</span> 为 <strong>False</strong> 外，其他都为 <strong>True</strong> 例如：</p>
<pre>&gt;&gt;&gt; bool(-2)
True
&gt;&gt;&gt; bool('')
False</pre>

<div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="../note/30201">王二的弟弟</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;王二的弟弟</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;182***56065@163.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://blog.csdn.net/fei_gao/article/details/5914759">&nbsp;&nbsp;参考地址</a></p></div></span>5年前 (2018-07-25)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-38332"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;健子</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;136***9943@qq.com</p></div><div id="runoobvote-id-38332" data-commid = "38332" class="upvotejs"><a class="upvote"></a> <span class="count">60</span></div></div><div class="comt-main" id="div-comment-38332"><p>对应<span class="marked"><a href="#11702" rel="nofollow">一楼</a></span>，函数的参数为多个时，不一定是以元组的形式返回的，还是要看自己定义的返回形式是什么:</p>

<pre>&gt;&gt;&gt; def example(a,b):
...     return (a,b)
... 
&gt;&gt;&gt; type(example(3,4))
&lt;type 'tuple'&gt;
&gt;&gt;&gt; def example(a,b):
...     return a,b
... 
&gt;&gt;&gt; type(example(3,4))
&lt;type 'tuple'&gt;
&gt;&gt;&gt; def example(a,b):
...     return [a,b]
... 
&gt;&gt;&gt; type(example(3,4))
&lt;type 'list'&gt;</pre>
<div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">健子</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;健子</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;136***9943@qq.com</p></div></span>4年前 (2018-12-25)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-39122"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;went000</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;751***610@qq.com</p></div><div id="runoobvote-id-39122" data-commid = "39122" class="upvotejs"><a class="upvote"></a> <span class="count">95</span></div></div><div class="comt-main" id="div-comment-39122"><p>针对楼上对一楼的观点提出的不同意见，但是一楼实际说的是返回值有多个时，而非楼上说的参数为多个。</p>

<pre>&gt;&gt;&gt; type(example(3,4))
&lt;type 'tuple'&gt;
&gt;&gt;&gt; def example(a,b):
...     return [a,b]
... 
&gt;&gt;&gt; type(example(3,4))
&lt;type 'list'&gt;</pre>
<p>以上实际返回值也只有一个，一个 List 类型的参数。</p>

<p>一楼所说的返回值为多个是：</p>

<pre>&gt;&gt;&gt; type(example(3,4))
&lt;type 'tuple'&gt;
&gt;&gt;&gt; def example(a,b):
...     return a,b
... 
&gt;&gt;&gt; type(example(3,4))
&lt;type 'tuple'&gt;</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">went000</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;went000</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;751***610@qq.com</p></div></span>4年前 (2019-01-18)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-40449"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;flaray</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;144***3921@qq.com</p></div><div id="runoobvote-id-40449" data-commid = "40449" class="upvotejs"><a class="upvote"></a> <span class="count">32</span></div></div><div class="comt-main" id="div-comment-40449"><p><strong>Bool 型小知识 :</strong></p>
<ul><li>
Python2 支持：int、float、long、complex（复数）</li><li>
Python3 支持：int、float、bool、complex（复数）</li></ul>
<p>Python3 废除了 long 类型，将 0 和 1 独立出来组成判断对错的 Bool 型，即 0 和 1 可以用来判断 flase 和 true。但是根本上并没有修改原则。这里的 Bool 型依然是 int 型的一部分，所以依然能当做数字参与运算，所以 Python3 里的 Bool 型是 int 型的一个特例而不是一个独立的类型。</p>
<div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">flaray</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;flaray</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;144***3921@qq.com</p></div></span>4年前 (2019-03-06)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-41759"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;甄能忽悠呀</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;813***866@qq.com</p></div><div id="runoobvote-id-41759" data-commid = "41759" class="upvotejs"><a class="upvote"></a> <span class="count">64</span></div></div><div class="comt-main" id="div-comment-41759"><p>注意：列表、元组、集合有所区别(新人特别容易入坑)。</p>

<p>列表和元组不会把相同的值合并，但是集合会把相同的合并。</p>

<pre>&gt;&gt;&gt; clist = ['tom','tom','jerry']                #测试列表功能
&gt;&gt;&gt; print (clist）
['tom','tom','jerry']

&gt;&gt;&gt;ctuple = ('tom','tom','jerry')           #测试元组功能
&gt;&gt;&gt;print(ctuple)
('tom','tom','jerry') 

&gt;&gt;&gt;cset = {'tom','tom','jerry'}                #测试集合功能
&gt;&gt;&gt;print(cset)
{'tom','jerry'}</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">甄能忽悠呀</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;甄能忽悠呀</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;813***866@qq.com</p></div></span>4年前 (2019-04-11)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-47232"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;dianmouren</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;yan***i4242@outlook.com</p></div><div id="runoobvote-id-47232" data-commid = "47232" class="upvotejs"><a class="upvote"></a> <span class="count">37</span></div></div><div class="comt-main" id="div-comment-47232"><p>关于列表的创建细节补充：</p>

<pre>&gt;&gt;&gt; o = {1, 2, 3}
&gt;&gt;&gt; type(o)
&lt;class 'set'&gt;
&gt;&gt;&gt; o = {}
&gt;&gt;&gt; type(o)
&lt;class 'dict'&gt;</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">dianmouren</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;dianmouren</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;yan***i4242@outlook.com</p></div></span>4年前 (2019-10-05)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-50333"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;紫竹修韵</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;162***3732@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://www.cnblogs.com/xiaoyh/p/9980311.html">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-50333" data-commid = "50333" class="upvotejs"><a class="upvote"></a> <span class="count">37</span></div></div><div class="comt-main" id="div-comment-50333"><p>关于字典推导式的一些案例：</p>
'''
<pre># 字典推导式
p = {i:str(i) for i in range(1,5)}
print("p:",p)
'''
p: {1: '1', 2: '2', 3: '3', 4: '4'}
'''

x = ['A','B','C','D']
y = ['a','b','c','d']
n = {i:j for i,j in zip(x,y)}
print("n:",n)
'''
n: {'A': 'a', 'B': 'b', 'C': 'c', 'D': 'd'}
'''

s = {x:x.strip() for x in ('he','she','I')}
print("s:",s)
'''
s: {'he': 'he', 'she': 'she', 'I': 'I'}
'''</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">紫竹修韵</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;紫竹修韵</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;162***3732@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://www.cnblogs.com/xiaoyh/p/9980311.html">&nbsp;&nbsp;参考地址</a></p></div></span>3年前 (2020-01-29)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-55907"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Creepercdn</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;cre***rcdn@outlook.com</p></div><div id="runoobvote-id-55907" data-commid = "55907" class="upvotejs"><a class="upvote"></a> <span class="count">46</span></div></div><div class="comt-main" id="div-comment-55907"><p><b>所有数据类型都是类。</b></p><p>也就是说，int、str等数据类型不是函数，只是一个类罢了。</p><p>用int()、str()、list()等都是初始化相应的类，那么123456、"Runoob“、[1,2,3] 等都是相应数据类型的初始化结果。</p><p>有很多人和教学网站都认为int、str、list等数据类型都是函数，但这是错误的。type(int)的输出结果表明int是一个类。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">Creepercdn</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Creepercdn</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;cre***rcdn@outlook.com</p></div></span>3年前 (2020-08-03)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-61522"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;闫伟超</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;yif***chaoran@163.com</p></div><div id="runoobvote-id-61522" data-commid = "61522" class="upvotejs"><a class="upvote"></a> <span class="count">74</span></div></div><div class="comt-main" id="div-comment-61522"><p>此处延伸下变量和对象之间的关系：</p><ul><li>赋值操作，本质是创建引用</li><li>变量是变量，对象是对象，当将某个对象赋值给某个变量时，可以认为是创建了变量对该对象的引用</li><li>变量没有数据类型之说，只有对象有，即变量不是直接代表对象或对象占用的内存空间</li><li>Python中，变量无需提前声明，无需指定其数据类型，其表现完全是动态的，其所为的数据类型决定于当前该变量所引用的对象的数据类型</li><li>所谓变量对对象的引用，本质是创建了变量指向对象内存空间的指针</li><li>对象内存空间，一般最起码有类型和当前被引用次数这两个信息，类型记录了该对象的数据类型，被引用次数记录了该对象内存空间被变量引用的次数</li><li>当某对象的被引用次数为0时，Python便会自动回收该对象内存空间</li></ul><p>比如下面的</p><pre>a=10
a='122'
a=[1,2,3]
del a</pre><p>此时，a在不同的赋值代码行中，引用的对象类型不同，相当于在不断改变a引用的对象，最后当把a变量删除时，其实本质只是删除了a变量名，但由于a引用的[1,2,3]对象，因为a被删除，其被引用次数变为0，也就自动被Python回收，最终表现就是del a时，[1,2,3]也被删除了。</p><p>另外一个小知识是，Python为提升代码执行和内存分配效率，会对一些常用的对象提前创建好，并常驻内存，比如下面：</p><pre>id(4) #不管运行多少次该代码，其返回的值均不变，因为python会保持一些常用的数字常驻内存，不会每次都重新分配内存空间
id('hello world') #每次运行，返回的值均会发生变化，因为每次运行，相当于都在重新分配内存空间</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">闫伟超</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;闫伟超</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;yif***chaoran@163.com</p></div></span>2年前 (2021-02-20)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-69682"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;elliotalderson</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;274***2424@qq.com</p></div><div id="runoobvote-id-69682" data-commid = "69682" class="upvotejs"><a class="upvote"></a> <span class="count">25</span></div></div><div class="comt-main" id="div-comment-69682"><p>type的意思可以理解为：检查这个变量本身的类型，而不用管他的父类的类型</p><p>isinstance的意思可以理解为：判断这个变量的类型是不是属于某一个大类，就好像找家谱一样，判断你是不是这个家族的人</p><p>is用来不仅会对比数值是否一样，还会对比类型是否相同，并且是不是对比父类类型</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">elliotalderson</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;elliotalderson</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;274***2424@qq.com</p></div></span>1年前 (2022-01-16)</div></div></li><!-- #comment-## -->
	</ol>
	<div class="pagenav">
			</div>
</div>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style="display:none; padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='9367' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  9367;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 9367, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":9367},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
		<div class="sidebar-box ">
				

<style>	
.responsive_ad1 { display:none; }
@media(min-width: 800px) { .responsive_ad1 {  display:block;margin:0 auto;} }
</style>
<div id="ad-336280" >

<script async src=""
     crossorigin="anonymous"></script>
<!-- 移动版 自动调整 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="1691338467"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
				</div>
		
	</div>
</div>
	

<!-- 右边栏 -->
<div class="fivecol last right-column">

<style>
.sidebar-tree .double-li {
    width:300px;
}
.sidebar-tree .double-li li {
    width: 44%;
    line-height: 1.5em;
    border-bottom: 1px solid #ccc;
    float: left;
    display: inline;
}
</style>

    
        <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here" style="margin: 0 auto;">
            <a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;"> <i class="fa fa-list" aria-hidden="true"></i> 分类导航</a>
        </div>
    <div class="sidebar-box sidebar-cate">
        
        <div class="sidebar-tree" >
            <ul><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> HTML / CSS</a><ul class="double-li"><li><a title="HTML 教程" href="../html/html-tutorial.html">HTML 教程</a></li><li><a title="HTML5 教程" href="../html/html5-intro.html">HTML5 教程</a></li><li><a title="CSS 教程" href="../css/css-tutorial.html">CSS 教程</a></li><li><a title="CSS3 教程" href="../css3/css3-tutorial.html">CSS3 教程</a></li><li><a title="Bootstrap3 教程" href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程</a></li><li><a title="Bootstrap4 教程" href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程</a></li><li><a title="Bootstrap5 教程" href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程</a></li><li><a title="Font Awesome 教程" href="../font-awesome/fontawesome-tutorial.html">Font Awesome 教程</a></li><li><a title="Foundation 教程" href="../foundation/foundation-tutorial.html">Foundation 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> JavaScript</a><ul class="double-li"><li><a title="JavaScript 教程" href="../js/js-tutorial.html">JavaScript 教程</a></li><li><a title="HTML DOM 教程" href="../htmldom/htmldom-tutorial.html">HTML DOM 教程</a></li><li><a title="jQuery 教程" href="../jquery/jquery-tutorial.html">jQuery 教程</a></li><li><a title="AngularJS 教程" href="../angularjs/angularjs-tutorial.html">AngularJS 教程</a></li><li><a title="AngularJS2 教程" href="../angularjs2/angularjs2-tutorial.html">AngularJS2 教程</a></li><li><a title="Vue.js 教程" href="../vue2/vue-tutorial.html">Vue.js 教程</a></li><li><a title="Vue3 教程" href="../vue3/vue3-tutorial.html">Vue3 教程</a></li><li><a title="React 教程" href="../react/react-tutorial.html">React 教程</a></li><li><a title="TypeScript 教程" href="../typescript/ts-tutorial.html">TypeScript 教程</a></li><li><a title="jQuery UI 教程" href="../jqueryui/jqueryui-tutorial.html">jQuery UI 教程</a></li><li><a title="jQuery EasyUI 教程" href="../jeasyui/jqueryeasyui-tutorial.html">jQuery EasyUI 教程</a></li><li><a title="Node.js 教程" href="../nodejs/nodejs-tutorial.html">Node.js 教程</a></li><li><a title="AJAX 教程" href="../ajax/ajax-tutorial.html">AJAX 教程</a></li><li><a title="JSON 教程" href="../json/json-tutorial.html">JSON 教程</a></li><li><a title="Echarts 教程" href="../echarts/echarts-tutorial.html">Echarts 教程</a></li><li><a title="Chart.js 教程" href="../chartjs/chartjs-tutorial.html">Chart.js 教程</a></li><li><a title="Highcharts 教程" href="../highcharts/highcharts-tutorial.html">Highcharts 教程</a></li><li><a title="Google 地图 教程" href="../googleapi/google-maps-basic.html">Google 地图 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 服务端</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="Python2.x 教程" href="../python/python-tutorial.html">Python2.x 教程</a></li><li><a title="Linux 教程" href="../linux/linux-tutorial.html">Linux 教程</a></li><li><a title="Docker 教程" href="../docker/docker-tutorial.html">Docker 教程</a></li><li><a title="Ruby 教程" href="../ruby/ruby-tutorial.html">Ruby 教程</a></li><li><a title="Java 教程" href="../java/java-tutorial.html">Java 教程</a></li><li><a title="C 教程" href="../c/c-tutorial.html">C 教程</a></li><li><a title="C++ 教程" href="../cplusplus/cpp-tutorial.html">C++ 教程</a></li><li><a title="Perl 教程" href="../perl/perl-tutorial.html">Perl 教程</a></li><li><a title="Servlet 教程" href="../servlet/servlet-tutorial.html">Servlet 教程</a></li><li><a title="JSP 教程" href="../jsp/jsp-tutorial.html">JSP 教程</a></li><li><a title="Lua 教程" href="../lua/lua-tutorial.html">Lua 教程</a></li><li><a title="Rust 教程" href="../rust/rust-tutorial.html">Rust 教程</a></li><li><a title="Scala 教程" href="../scala/scala-tutorial.html">Scala 教程</a></li><li><a title="Go 教程" href="../go/go-tutorial.html">Go 教程</a></li><li><a title="PHP 教程" href="../php/php-tutorial.html">PHP 教程</a></li><li><a title="数据结构与算法" href="../data-structures/data-structures-tutorial.html">数据结构与算法</a></li><li><a title="Django 教程" href="../django/django-tutorial.html">Django 教程</a></li><li><a title="Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html">Zookeeper 教程</a></li><li><a title="设计模式" href="../design-pattern/design-pattern-tutorial.html">设计模式</a></li><li><a title="正则表达式" href="../regexp/regexp-tutorial.html">正则表达式</a></li><li><a title="Maven 教程" href="../maven/maven-tutorial.html">Maven 教程</a></li><li><a title="Verilog 教程" href="../w3cnote/verilog-tutorial.html">Verilog 教程</a></li><li><a title="ASP 教程" href="../asp/asp-tutorial.html">ASP 教程</a></li><li><a title="AppML 教程" href="../appml/appml-tutorial.html">AppML 教程</a></li><li><a title="VBScript 教程" href="../vbscript/vbscript-tutorial.html">VBScript 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据库</a><ul class="double-li"><li><a title="SQL 教程" href="../sql/sql-tutorial.html">SQL 教程</a></li><li><a title="MySQL 教程" href="../mysql/mysql-tutorial.html">MySQL 教程</a></li><li><a title="PostgreSQL 教程" href="../postgresql/postgresql-tutorial.html">PostgreSQL 教程</a></li><li><a title="SQLite 教程" href="../sqlite/sqlite-tutorial.html">SQLite 教程</a></li><li><a title="MongoDB 教程" href="../mongodb/mongodb-tutorial.html">MongoDB 教程</a></li><li><a title="Redis 教程" href="../redis/redis-tutorial.html">Redis 教程</a></li><li><a title="Memcached 教程" href="../Memcached/Memcached-tutorial.html">Memcached 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据分析</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="NumPy 教程" href="../numpy/numpy-tutorial.html">NumPy 教程</a></li><li><a title="Pandas 教程" href="../pandas/pandas-tutorial.html">Pandas 教程</a></li><li><a title="Matplotlib 教程" href="../matplotlib/matplotlib-tutorial.html">Matplotlib 教程</a></li><li><a title="Scipy 教程" href="../scipy/scipy-tutorial.html">Scipy 教程</a></li><li><a title="R 教程" href="../r/r-tutorial.html">R 教程</a></li><li><a title="Julia 教程" href="../julia/julia-tutorial.html">Julia 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 移动端</a><ul class="double-li"><li><a title="Android 教程" href="../w3cnote/android-tutorial-intro.html">Android 教程</a></li><li><a title="Swift 教程" href="../swift/swift-tutorial.html">Swift 教程</a></li><li><a title="jQuery Mobile 教程" href="../jquerymobile/jquerymobile-tutorial.html">jQuery Mobile 教程</a></li><li><a title="ionic 教程" href="../ionic/ionic-tutorial.html">ionic 教程</a></li><li><a title="Kotlin 教程" href="../kotlin/kotlin-tutorial.html">Kotlin 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> XML 教程</a><ul class="double-li"><li><a title="XML 教程" href="../xml/xml-tutorial.html">XML 教程</a></li><li><a title="DTD 教程" href="../dtd/dtd-tutorial.html">DTD 教程</a></li><li><a title="XML DOM 教程" href="../dom/dom-tutorial.html">XML DOM 教程</a></li><li><a title="XSLT 教程" href="../xsl/xsl-tutorial.html">XSLT 教程</a></li><li><a title="XPath 教程" href="../xpath/xpath-tutorial.html">XPath 教程</a></li><li><a title="XQuery 教程" href="../xquery/xquery-tutorial.html">XQuery 教程</a></li><li><a title="XLink 教程" href="../xlink/xlink-tutorial.html">XLink 教程</a></li><li><a title="XPointer 教程" href="../xlink/xlink-tutorial.html">XPointer 教程</a></li><li><a title="XML Schema 教程" href="../schema/schema-tutorial.html">XML Schema 教程</a></li><li><a title="XSL-FO 教程" href="../xslfo/xslfo-tutorial.html">XSL-FO 教程</a></li><li><a title="SVG 教程" href="../svg/svg-tutorial.html">SVG 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> ASP.NET</a><ul class="double-li"><li><a title="ASP.NET 教程" href="../aspnet/aspnet-tutorial.html">ASP.NET 教程</a></li><li><a title="C# 教程" href="../csharp/csharp-tutorial.html">C# 教程</a></li><li><a title="Web Pages 教程" href="../aspnet/webpages-intro.html">Web Pages 教程</a></li><li><a title="Razor 教程" href="../aspnet/razor-intro.html">Razor 教程</a></li><li><a title="MVC 教程" href="../aspnet/mvc-intro.html">MVC 教程</a></li><li><a title="Web Forms 教程" href="../aspnet/aspnet-intro.html">Web Forms 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> Web Service</a><ul class="double-li"><li><a title="Web Service 教程" href="../webservices/webservices-tutorial.html">Web Service 教程</a></li><li><a title="WSDL 教程" href="../wsdl/wsdl-tutorial.html">WSDL 教程</a></li><li><a title="SOAP 教程" href="../soap/soap-tutorial.html">SOAP 教程</a></li><li><a title="RSS 教程" href="../rss/rss-tutorial.html">RSS 教程</a></li><li><a title="RDF 教程" href="../rdf/rdf-tutorial.html">RDF 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 开发工具</a><ul class="double-li"><li><a title="Eclipse 教程" href="../eclipse/eclipse-tutorial.html">Eclipse 教程</a></li><li><a title="Git 教程" href="../git/git-tutorial.html">Git 教程</a></li><li><a title="Svn 教程" href="../svn/svn-tutorial.html">Svn 教程</a></li><li><a title="Markdown 教程" href="../markdown/md-tutorial.html">Markdown 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 网站建设</a><ul class="double-li"><li><a title="HTTP 教程" href="../http/http-tutorial.html">HTTP 教程</a></li><li><a title="网站建设指南" href="../web/web-buildingprimer.html">网站建设指南</a></li><li><a title="浏览器信息" href="../browsers/browser-information.html">浏览器信息</a></li><li><a title="网站主机教程" href="../hosting/hosting-tutorial.html">网站主机教程</a></li><li><a title="TCP/IP 教程" href="../tcpip/tcpip-tutorial.html">TCP/IP 教程</a></li><li><a title="W3C 教程" href="../w3c/w3c-tutorial.html">W3C 教程</a></li><li><a title="网站品质" href="../quality/quality-tutorial.html">网站品质</a></li></ul></li></ul>            </div>
    
    </div>
    </div>
    <br>
    
    <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here">
            <a href="javascript:void(0);">Advertisement</a>
        </div>
        <div class="re-600160" id="sidebar-right-re">
                <script async src=""></script>
        <!-- 侧栏1 -->
        <ins class="adsbygoogle"
             style="display:inline-block;width:160px;height:600px"
             data-ad-client="ca-pub-5751451760833794"
             data-ad-slot="4106274865"></ins>
        <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
                </div>
    </div>
</div></div>

</div>

<script>
var aid = 9367;
function coll() {
	$.post( '/wp-content/themes/runoob/option/user/userinfo.php', {aid:aid, action:"collarticle", opt:'add'},function( data ) {
		if(data.error==0) {
			$("#content").find("h1:first").find("a").attr("href","javascript:void(0);");
			$("#content").find("h1:first").find("img").attr("src","http://www.runoob.com/wp-content/themes/runoob/assets/img/coll2.png").css({width:32+"px",height:32+"px"});
		}
		alert(data.msg);
	},'json');
}
</script>


<!-- 反馈对话框开始 -->
<script src=""></script>
<link rel="stylesheet" href="../0/feedback.css?1.0" />
<script type="text/javascript">
$.feedback({
    ajaxURL: '/feedback/runoob_feedback.php',
	html2canvasURL: '/wp-content/themes/runoob/assets/feedback/stable/2.0/html2canvas.js',
	onClose: function () {
         window.location.reload();
    }
});
</script>
<!-- 反馈对话框结束 -->
<button class="feedback-btn feedback-btn-gray">反馈/建议</button>
<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>